<%--
  Created by IntelliJ IDEA.
  User: lichengming
  Date: 2017/6/14
  Time: 下午4:38
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/resources.jsp" %>


<html>
<head>
    <title>接口列表</title>
</head>
<body>
<div>
    <div class="panel panel-default">
        <div class="panel-heading">
            <h3 class="panel-title">查询条件</h3>
        </div>
        <div class="panel-body">
            <form class="form-inline">
                <div class="form-group">
                    <label for="searchName">接口：</label>
                    <input type="text" class="form-control" id="searchName" name="name" placeholder="接口">
                </div>
                <div class="form-group">
                    <label for="searchModuleName">模块：</label>
                    <input type="text" class="form-control" id="searchModuleName" name="moduleName" placeholder="模块">
                </div>
                <button type="button" class="btn btn-info btn-search">查询</button>
                <button type="button" class="btn btn-default btn-reset">清空</button>
            </form>
        </div>
    </div>
</div>

<div class="ems_table_content">
    <div class="panel panel-default">
        <div class="panel-heading">接口列表</div>
        <div id="table_tools">
            <div class="form-inline" role="form">
                <button type="button" id="interface_add" class="btn btn-outline btn-success">
                    <i class="glyphicon glyphicon-plus" aria-hidden="true"></i>
                    添加
                </button>
                <button type="button" id="interface_edit" class="btn btn-outline btn-primary">
                    <i class="glyphicon glyphicon-edit" aria-hidden="true"></i>
                    修改
                </button>
                <button type="button" id="interface_delete" class="btn btn-outline btn-danger">
                    <i class="glyphicon glyphicon-trash" aria-hidden="true"></i>
                    删除
                </button>
            </div>
        </div>
        <table id="interfaceTable"
               data-url="/ems/interface/pagination"
               data-show-export="true">
            <thead>
            <tr>
                <th data-field="state" data-checkbox="true"></th>
                <th data-field="name">接口</th>
                <th data-field="url">uri</th>
                <th data-field="system_name">系统</th>
                <th data-field="module_name">模块</th>
                <th data-field="status" data-formatter="statusFormat">状态</th>
            </tr>
            </thead>
        </table>
    </div>
</div>
<script>
    function statusFormat(srcValue) {
        if (srcValue == 1) {
            return "<span style='color: #3cb371;font-weight: bold' >正常</span>";
        }else {
            return "<span style='color: red;font-weight: bold'>已废弃</span>";
        }
    }
</script>

<script>
    $(function () {

        //初始化表格
        $("#interfaceTable").createTable();

        //添加
        $("#interface_add").on("click",function () {
            window.location.href = "/ems/interface/edit"
        })

        //编辑
        $("#interface_edit").on("click",function () {
           var selectRows =  $('#interfaceTable').bootstrapTable('getSelections');
           if (selectRows.length == 0) {
               $.errorAlert("请选择要编辑的数据");
               return;
           }
           if (selectRows.length > 1) {
               $.errorAlert("暂时不支持多行数据编辑");
               return;
           }
           window.location.href = "/ems/interface/edit?id=" + selectRows[0].id;
        })

        //删除
        $("#interface_delete").on("click",function () {
            var selectRows =  $('#interfaceTable').bootstrapTable('getSelections');
            if (selectRows.length == 0) {
                $.errorAlert("请选择要删除的数据");
                return;
            }

            var interfaceIdList = "";
            for (var i = 0;i<selectRows.length;i++) {
                interfaceIdList += selectRows[i].id + ",";
            }
            interfaceIdList = interfaceIdList.substring(0,interfaceIdList.length - 1);
            $.emsAjax({
                data:{interfaceIdList:interfaceIdList},
                type:"POST",
                url:"/ems/interface/delete",
                success:function(resp) {
                    if (resp.status == "000") {
                        $.alert(resp.message);
                        search("#interfaceTable",getQueryParams());
                    }else {
                        $.errorAlert(resp.message);
                    }
                }
            });
        });
    })
</script>
</body>
</html>
